package cn.controller;


import cn.pojo.User;
import cn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
@RequestMapping("/mybatistest")
public class MybatisController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "ins")
    @ResponseBody
    public String string() {
        User user = new User();
        user.setId(3);
        user.setUsername("Tom");
        user.setAddress("Asia");
        user.setBirthday(new Date());
        userService.insert(user);
        return "success";
    }

    @RequestMapping(value = "getuser")
    public ModelAndView getUser() {
        User user = userService.selectById(3);
        System.out.println(user.getBirthday());
        return new ModelAndView("getuser", "user", user);
    }
}
